package com.example.day01


fun a() {
    class person {
        val name = "🐕"
        var age = 18

        init {
            println("${name}")
        }
    }

    val gold = person()
    println(gold.name)
}

fun b() {
    class person(ame: String, age: Int) {
        val name = ame
        var age = age

    }

    val gold = person("Dog", 18)
    println(gold.name)
}

fun c() {
    class fish(var name: String) {
        var age: Int = 0
        var colo: String = "black"

        init {
//            println("${name}")
        }

        constructor(name: String, age: Int) : this(name) {
            this.age = age
        }

        constructor(name: String, age: Int, colo: String) : this(name, age) {
            this.colo = colo

        }
    }
    println(fish("Dog", 18).age)
    println(fish("Dog", 18, "white").colo)
}

fun d() {
    open class cat(val name: String, val age: Int) {
        open fun eat() {
            println("chiyu")
        }
    }

    class newcat(name: String, age: Int) : cat(name, age) {
        override fun eat() {
            println("buchiyu")
        }
    }

    val gold = newcat("鲈鱼", 1)
    println(gold.eat())
    println(gold.name)
}

fun f() {
    data class conputer(
        val name: String,
        val price: Int,
        var color: String
    )

    val myComputer = conputer("thinkpad", 7800, "黑")
    println(myComputer)
    val myconputer = myComputer.copy()
    println(myconputer == myComputer)

    val (name, price, color) = myComputer
    println("$name $price $color")
}

fun g() {
    val myCar = carID
    myCar.ID
    println(myCar.ID)
}

//生成入口函数
interface Dog {
    val name: String
    fun eat()
}

fun e() {
    class NewDog : Dog {
        override val name: String = "Dog"
        override fun eat() {
            println("chiyu")
        }
    }

    val myDog = NewDog()
    println(myDog.name)
    myDog.eat()
}

fun h() {
    val list = listOf(1, 2, 3, 4, 5, 65, 7)
    val data = listOf("mac", "thinkpad", "外星人")
    println(list)
    println(data)

    val newlist = list.map { it * 2 }
    println(newlist)
    data.forEach({ it -> println(it) })

    var list2 = list.toMutableList()
    list2.add(6, 7)
    list2.add(998)
    list2.addAll(listOf(123, 123, 998))
    list2.remove(123)
    list2.remove(998)
    list2.add(998)
    list2.removeAll(listOf(998))
    println(list2)
}

object carID {
    val ID: Int = 123
}

fun main() {

    class cat {
        var name: String = "Dog"
        var age: Int = 18
        fun eat() {
            println("chiyu")
        }
    }

    val mycat = cat().apply {
        name = "ggw"
        age = 1
        fun eat() {
            println("quliulan")
        }
    }
    println(mycat.age)
    println(mycat.name)
    println(mycat.eat())

}